package com.goldcontrol.cloudweb.quartz.job;

import com.goldcontrol.cloudweb.common.Constants;
import com.goldcontrol.cloudweb.mapper.ProjectControlMapper;
import com.goldcontrol.cloudweb.model.ProjectControl;
import com.goldcontrol.cloudweb.weixin.service.WeixinServiceApi;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CtrlJob implements Job {

    private Logger logger = LoggerFactory.getLogger(CtrlJob.class);

    @Autowired
    WeixinServiceApi weixinServiceApi;

    @Autowired
    ProjectControlMapper projectControlMapper;

    @Override
    public void execute(JobExecutionContext jobExecutionContext){
        try{
            Map<String,Object> map = new HashMap<>();
            map.put("control",1);
            List<ProjectControl> list = projectControlMapper.selectByFields(map);
            for(ProjectControl projectControl : list){
                weixinServiceApi.autoControlTemp(Constants.TOKEN,projectControl.getProjectId());
            }
        }catch (Exception e){
            logger.error("定时任务控制失败",e);
        }
    }

}
